package com.tianqingwl.gsystem.common.config;

import com.google.code.kaptcha.servlet.KaptchaServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class ServletConfig {

    @Bean
    public ServletRegistrationBean servletRegistrationBean(){

        KaptchaServlet kaptchaServlet = new KaptchaServlet();


        ServletRegistrationBean bean = new ServletRegistrationBean(kaptchaServlet);

        bean.addUrlMappings("/captcha");
        Map<String,String> initParam = new HashMap<>();
        initParam.put("kaptcha.border","no");
        initParam.put("kaptcha.textproducer.font.color","red");
        initParam.put("kaptcha.image.width","135");
        initParam.put("kaptcha.image.height","50");
        initParam.put("kaptcha.textproducer.char.string","ACDEFHKPRSTWX345679");
        initParam.put("kaptcha.textproducer.font.size","32");
        initParam.put("kaptcha.noise.color","black");
        initParam.put("kaptcha.textproducer.char.length","6");
        initParam.put("kaptcha.textproducer.font.names","Arial");
        bean.setInitParameters(initParam);
        return bean;
    }
}
